/*
2021-7-21
https://www.acwing.com/problem/content/92/
*/
#include<iostream>

using namespace std;
typedef long long ll;
ll a,b,p;
ll qadd(ll a,ll b)
{
    ll res=0;
    while(b)
    {
        if(b&1)
        {
            res=(res+a)%p;
        }
        a=(a+a)%p;
        b>>=1;
    }
    return res;
}

int main()
{
    cin>>a>>b>>p;
    
    cout<<qadd(a,b)<<endl;
    
    return 0;
}
